import 'package:changxindianzishangwu/util/app_color.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///通用页面
///错误页面 提供按钮重新调用接口
class PageState {
  static const String PAGE_LOADING = "pageLoadingState";
  static const String PAGE_EMPTY = "pageEmptyState";
  static const String PAGE_ERROR = "pageErrorState";
}

class CommonPage {
  Widget error(Function function) {
    return Container(
        color: AppColor.bg,
        child: Center(
          child: TextButton(
              onPressed: function,
              child: Text(
                "错误页面，点击重新访问接口",
                style: TextStyle(fontSize: 20, color: AppColor.colorTheme),
              )),
        ));
  }

  static Widget loading(Function function,
      {String state = PageState.PAGE_LOADING, String title = "暂无内容"}) {
    return state == PageState.PAGE_LOADING
        ? Container(
          child: Center(
            child: CircularProgressIndicator(
                valueColor: AlwaysStoppedAnimation<Color>(AppColor.colorTheme),
                backgroundColor: Color(0xccffffff),
                strokeWidth: 3,
              ),
          ),
        )
        : Container(
            child: Column(
            children: [
              Image.asset(
                "images/ic_empty_logo.png",
                height: height(170),
              ),
              Text(title),
              state == PageState.PAGE_ERROR
                  ? Container(
                      margin: EdgeInsets.only(top: height(60)),
                      child: TextButton(
                          onPressed: function,
                          child: Text(
                            title,
                            style: TextStyle(
                                color: Colors.white, fontSize: sp(15)),
                          ),
                          style: ButtonStyle(
                            textStyle: MaterialStateProperty.all(
                              TextStyle(
                                fontSize: ScreenUtil().setSp(15),
                                color: Colors.white,
                              ),
                            ),
                            backgroundColor:
                                MaterialStateProperty.all(AppColor.colorTheme),
                            padding:
                                MaterialStateProperty.all(EdgeInsets.all(10)),
                            minimumSize: MaterialStateProperty.all(
                                Size(width(100), height(44))),
                          )),
                    )
                  : SizedBox(),
            ],
          ));
  }
}
